from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.models.user import User
from app.core.config import settings

# 创建数据库连接
engine = create_engine(settings.DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()

try:
    # 查找用户 jhj
    user = db.query(User).filter(User.username == 'jhj').first()
    
    if user:
        # 设置为管理员
        user.role = 'admin'
        user.is_admin = True
        user.status = 'active'
        db.commit()
        print(f"用户 {user.username} 已成功设置为管理员")
    else:
        print("未找到用户 jhj")
        
except Exception as e:
    print(f"发生错误: {e}")
    db.rollback()
finally:
    db.close() 